package cn.dengta.webapp.im.entity;

import java.math.BigDecimal;
import java.util.Date;

import cn.dengta.context.model.WesKit;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Cmp;
import me.codeplayer.util.X;

/**
 * 免费搭讪补贴统计
 *
 * @author lgy
 * @since 2022-12-22
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("im_free_greet_subsidy_statistics")
public class FreeGreetSubsidyStatistics extends TimeBasedEntity {

	public static final String BACK_FEMALE_COUNT = "msg:back_female_count:";

	/** 使用免费搭讪次数 */
	Integer freeTimes;
	/** 免费搭讪获得积分 */
	BigDecimal freeIntegral;
	/** 使用完免费搭讪男用户数量 */
	Integer useUpFreeMaleCount;
	/** 额外奖励积分 */
	BigDecimal extraAwardIntegral;
	/** 女用户收益退回人数 */
	Integer integralBackFemaleCount;
	/** 统计日期 */
	Date reportTime;
	/** 分包 */
	private WesKit wesKit;

	public FreeGreetSubsidyStatistics init(FreeGreetSubsidyStatistics input, Date now) {
		this.freeTimes = X.expectNotNull(input.freeTimes, freeTimes);
		this.freeIntegral = X.expectNotNull(input.freeIntegral, freeIntegral);
		this.useUpFreeMaleCount = X.expectNotNull(input.useUpFreeMaleCount, useUpFreeMaleCount);
		this.extraAwardIntegral = X.expectNotNull(input.extraAwardIntegral, extraAwardIntegral);
		this.integralBackFemaleCount = X.expectNotNull(input.integralBackFemaleCount, integralBackFemaleCount);
		this.reportTime = X.expectNotNull(input.reportTime, reportTime);
		this.wesKit = X.expectNotNull(input.wesKit, wesKit);
		super.initTime(now);
		return this;
	}

	public FreeGreetSubsidyStatistics init(WesKit wesKit, Date reportTime) {
		this.freeTimes = 0;
		this.freeIntegral = BigDecimal.ZERO;
		this.useUpFreeMaleCount = 0;
		this.extraAwardIntegral = BigDecimal.ZERO;
		this.integralBackFemaleCount = 0;
		this.reportTime = reportTime;
		this.wesKit = wesKit;
		return this;
	}

	public FreeGreetSubsidyStatistics add(FreeGreetSubsidyStatistics input) {
		if (input != null) {
			if (Cmp.nullToZero(input.freeTimes) > 0) {
				this.freeTimes += input.freeTimes;
			}
			if (Cmp.nullToZero(input.freeIntegral).compareTo(BigDecimal.ZERO) > 0) {
				this.freeIntegral = this.freeIntegral.add(input.freeIntegral);
			}
			if (Cmp.nullToZero(input.useUpFreeMaleCount) > 0) {
				this.useUpFreeMaleCount += input.useUpFreeMaleCount;
			}
			if (Cmp.nullToZero(input.extraAwardIntegral).compareTo(BigDecimal.ZERO) > 0) {
				this.extraAwardIntegral = this.extraAwardIntegral.add(input.extraAwardIntegral);
			}
		}
		return this;
	}

	public static final String FREE_TIMES = "free_times";
	public static final String FREE_INTEGRAL = "free_integral";
	public static final String USE_UP_FREE_MALE_COUNT = "use_up_free_male_count";
	public static final String EXTRA_AWARD_INTEGRAL = "extra_award_integral";
	public static final String INTEGRAL_BACK_FEMALE_COUNT = "integral_back_female_count";
	public static final String REPORT_TIME = "report_time";
	public static final String WES_KIT = "wes_kit";

}
